# $1 - platform name
# $2 - runner workspace
# $3 - config
# $4 - toolset (MSVC)

cd "$2"
mkdir build
cd ./build

if [ "$1" = "win" ]; then
  cmake $GITHUB_WORKSPACE -G "Visual Studio 16 2019" -A $3 -DCMAKE_BUILD_TYPE=$4 $5 -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi

if [ "$1" = "uwp" ]; then
  cmake $GITHUB_WORKSPACE -G "Visual Studio 16 2019" -A $3 -DCMAKE_BUILD_TYPE=$4 $5 -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..
fi

if [ "$1" = "macos" ]; then
  cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$3 $4 -DVULKAN_SDK="$VULKAN_SDK" -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi

if [ "$1" = "ios" ]; then
  cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$3 $4 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES=arm64 -DVULKAN_SDK="$VULKAN_SDK" -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi

if [ "$1" = "tvos" ]; then
  cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$3 $4 -DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES=arm64 -DVULKAN_SDK="$VULKAN_SDK" -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi

if [ "$1" = "linux" ]; then
  cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$3 $4 -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi

if [ "$1" = "emscripten" ]; then
  emcmake cmake $GITHUB_WORKSPACE -G "Ninja" -DCMAKE_BUILD_TYPE=$3 $4 -DDILIGENT_NO_FORMAT_VALIDATION=ON -DCMAKE_INSTALL_PREFIX=install ..
fi
